package com.hdw.med.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hdw.common.util.SnowflakeIdWorker;
import com.hdw.common.vo.PaginationVO;
import com.hdw.med.api.BaseSdService;
import com.hdw.med.bean.model.BaseSd;
import com.hdw.med.mapper.BaseSdMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * baseSd服务实现类
 * Created by hozeData on 2021/05/21.
 */
@Service
@Transactional
public class BaseSdServiceImpl implements BaseSdService {

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseSdServiceImpl.class);

    @Autowired
    private BaseSdMapper baseSdMapper;

    @Override
    public int insert(BaseSd baseSd) {
        if(baseSd.getIdSd()==null){
            Long uuid32 = SnowflakeIdWorker.getId();
            baseSd.setIdSd(uuid32);
        }
        return baseSdMapper.insert(baseSd);
    }

    @Override
    public int insertSelective(BaseSd baseSd)  {
        if(baseSd.getIdSd()==null){
            Long uuid32 = SnowflakeIdWorker.getId();
            baseSd.setIdSd(uuid32);
        }
        return baseSdMapper.insertSelective(baseSd);
    }

    @Override
    public int deleteById(Long idSd)  {
        return baseSdMapper.deleteByPrimaryKey(idSd);
    }

    @Override
    public int updateByIdSelective(BaseSd baseSd)  {

        return baseSdMapper.updateByPrimaryKeySelective(baseSd);
    }

    @Override
    public int updateById(BaseSd baseSd)  {
        return baseSdMapper.updateByPrimaryKey(baseSd);
    }

    @Override
    public BaseSd getById(Long idSd)  {
        return baseSdMapper.selectByPrimaryKey(idSd);
    }

    @Override
    public List<BaseSd> findByModel(BaseSd baseSd)  {
        return baseSdMapper.findByModel(baseSd);
    }

    @Override
    public PaginationVO<BaseSd> findPageByModel(BaseSd baseSd, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<BaseSd> quesList = baseSdMapper.findByModel(baseSd);
        PageInfo<BaseSd> pageInfo = new PageInfo<>(quesList);
        PaginationVO<BaseSd> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

}
